package com.wysql.dalian.controller.getData;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wysql.dalian.service.DldpResultService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/dw-service-xxl-screen/TechScreenResultController")
@RequiredArgsConstructor
@Component
@CrossOrigin(origins = "*")
public class TechScreenResultController {

    private final DldpResultService dldpResultService;

    private static final String URL = "http://localhost:9055/techres/";

    @PostMapping("OneJson")
    @ResponseBody
    public Map<String, Object> getOne(@RequestBody(required = false) Map parammap, HttpServletRequest request, HttpServletResponse response) {
        //0、判断查询年份
        String year = "2023";
        if (parammap != null) {
            year = (String) parammap.get("year");
        }
        System.out.println("+++++++第一屏查询年份+++++" + year);

        //查询科技项目指南年度金额总数、项目总数
        String sql1 = "SELECT SUM(money) as money,count(*) as count FROM t_tech_guide WHERE year ="+year+"";
        Map<String, Object> result1 = dldpResultService.queryInfoBySql2(sql1);
        //查询揭榜挂帅制项目指南年度金额总数、项目总数
        String sql2 = "SELECT SUM(money) as money,count(*) as count FROM t_tech_guide WHERE year ="+year+" and memo = '揭榜挂帅制'";
        Map<String, Object> result2 = dldpResultService.queryInfoBySql2(sql2);
        BigDecimal jinezhanbi = new BigDecimal(result2.get("money").toString()).divide(new BigDecimal(result1.get("money").toString()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
        //查询揭榜挂帅制项目指南年度金额总数、项目总数
        String sql3 = "SELECT SUM(totalcost) as totalcost,SUM(yearcost) as yearcost,count(*) as count FROM t_tech_taskbook WHERE year ="+year+"";
        Map<String, Object> result3 = dldpResultService.queryInfoBySql2(sql3);
        BigDecimal taskzhanbi = new BigDecimal(result3.get("yearcost").toString()).divide(new BigDecimal(result3.get("totalcost").toString()),4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));

        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> res = new LinkedHashMap<>();
        //---------------top-------------------START
        Map<String, Object> topmap = new LinkedHashMap<>();
        //top->OverviewArry
        List<Map<String, Object>> top_OverviewArry = new ArrayList<>();
        Map<String, Object> top_OverviewArry_map1 = new LinkedHashMap<>();
        top_OverviewArry_map1.put("title", "科技项目申报指南");
        top_OverviewArry_map1.put("label1", "项目金额");
        top_OverviewArry_map1.put("value1", result1.get("money"));
        top_OverviewArry_map1.put("unit1", "万元");
        top_OverviewArry_map1.put("label2", "项目数量");
        top_OverviewArry_map1.put("value2", result1.get("count"));
        top_OverviewArry_map1.put("unit2", "个");
        top_OverviewArry_map1.put("value3", "0");
        top_OverviewArry_map1.put("unit3", "%");
        top_OverviewArry_map1.put("hasData", true);
        top_OverviewArry.add(top_OverviewArry_map1);
        Map<String, Object> top_OverviewArry_map2 = new LinkedHashMap<>();
        top_OverviewArry_map2.put("title", "揭榜挂帅制项目");
        top_OverviewArry_map2.put("label1", "项目金额");
        top_OverviewArry_map2.put("value1", result2.get("money"));
        top_OverviewArry_map2.put("unit1", "万元");
        top_OverviewArry_map2.put("label2", "项目数量");
        top_OverviewArry_map2.put("value2", result2.get("count"));
        top_OverviewArry_map2.put("unit2", "个");
        top_OverviewArry_map2.put("value3", jinezhanbi);
        top_OverviewArry_map2.put("unit3", "%");
        top_OverviewArry_map2.put("hasData", false);
        top_OverviewArry.add(top_OverviewArry_map2);
        Map<String, Object> top_OverviewArry_map3 = new LinkedHashMap<>();
        top_OverviewArry_map3.put("title", "下达科技项目任务");
        top_OverviewArry_map3.put("label1", "项目金额");
        top_OverviewArry_map3.put("value1", result3.get("totalcost"));
        top_OverviewArry_map3.put("unit1", "万元");
        top_OverviewArry_map3.put("label2", "项目数量");
        top_OverviewArry_map3.put("value2", result3.get("count"));
        top_OverviewArry_map3.put("unit2", "个");
        top_OverviewArry_map3.put("value3", "0");
        top_OverviewArry_map3.put("unit3", "%");
        top_OverviewArry_map3.put("hasData", true);
        top_OverviewArry.add(top_OverviewArry_map3);
        Map<String, Object> top_OverviewArry_map4 = new LinkedHashMap<>();
        top_OverviewArry_map4.put("title", "");
        top_OverviewArry_map4.put("label1", "年度经费");
        top_OverviewArry_map4.put("value1", result3.get("yearcost"));
        top_OverviewArry_map4.put("unit1", "万元");
        top_OverviewArry_map4.put("label2", "");
        top_OverviewArry_map4.put("value2", "");
        top_OverviewArry_map4.put("unit2", "");
        top_OverviewArry_map4.put("value3", taskzhanbi);
        top_OverviewArry_map4.put("unit3", "%");
        top_OverviewArry_map4.put("hasData", false);
        top_OverviewArry.add(top_OverviewArry_map4);
        topmap.put("OverviewArry", top_OverviewArry);
        //---------------top-------------------END
        String sql4 = "SELECT groupname groupname,count(*) count,SUM(money) money FROM t_tech_guide a WHERE a.year = "+year+" GROUP BY groupname";
        List<Map<String, Object>> maps = queryInfoBySql(sql4);

        BigDecimal totalMoney = new BigDecimal(result1.get("money").toString());
        BigDecimal totalCount = new BigDecimal(result1.get("count").toString());

        BigDecimal dlxtcount = BigDecimal.ZERO;
        BigDecimal sdcount = BigDecimal.ZERO;
        BigDecimal bdcount = BigDecimal.ZERO;
        BigDecimal pdcount = BigDecimal.ZERO;
        BigDecimal ydcount = BigDecimal.ZERO;
        BigDecimal xxtxcount = BigDecimal.ZERO;
        BigDecimal jczccount = BigDecimal.ZERO;

        BigDecimal dlxtmoney = BigDecimal.ZERO;
        BigDecimal sdmoney = BigDecimal.ZERO;
        BigDecimal bdmoney = BigDecimal.ZERO;
        BigDecimal pdmoney = BigDecimal.ZERO;
        BigDecimal ydmoney = BigDecimal.ZERO;
        BigDecimal xxtxmoney = BigDecimal.ZERO;
        BigDecimal jczcmoney = BigDecimal.ZERO;

        for (Map<String, Object> stringObjectMap : maps) {
            String groupname = (String) stringObjectMap.get("groupname");
            switch (groupname){
                case "电力系统":
                    dlxtcount = new BigDecimal(stringObjectMap.get("count").toString());
                    dlxtmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "输电":
                    sdcount = new BigDecimal(stringObjectMap.get("count").toString());
                    sdmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "变电":
                    bdcount = new BigDecimal(stringObjectMap.get("count").toString());
                    bdmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "配电":
                    pdcount = new BigDecimal(stringObjectMap.get("count").toString());
                    pdmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "用电":
                    ydcount = new BigDecimal(stringObjectMap.get("count").toString());
                    ydmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "信息通信":
                    xxtxcount = new BigDecimal(stringObjectMap.get("count").toString());
                    xxtxmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;
                case "决策支持":
                    jczccount = new BigDecimal(stringObjectMap.get("count").toString());
                    jczcmoney = new BigDecimal(stringObjectMap.get("money").toString());
                    break;

            }
        }

        //---------------mainleft-------------------START
        Map<String, Object> mainleftmap = new LinkedHashMap<>();
        List<Map<String, Object>> top_mainleftmap = new ArrayList<>();
        Map<String, Object> top_mainleftmap_map1 = new LinkedHashMap<>();
        top_mainleftmap_map1.put("title", "电力系统");
        top_mainleftmap_map1.put("label1", "项目数量");
        top_mainleftmap_map1.put("value1", dlxtcount);
        top_mainleftmap_map1.put("unit1", "个");
        top_mainleftmap_map1.put("label2", "项目金额");
        top_mainleftmap_map1.put("value2", dlxtmoney);
        top_mainleftmap_map1.put("unit2", "万元");
        top_mainleftmap_map1.put("value3", dlxtcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map1.put("unit3", "%");
        top_mainleftmap_map1.put("value4", dlxtmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map1.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map1);
        Map<String, Object> top_mainleftmap_map2 = new LinkedHashMap<>();
        top_mainleftmap_map2.put("title", "输电");
        top_mainleftmap_map2.put("label1", "项目数量");
        top_mainleftmap_map2.put("value1", sdcount);
        top_mainleftmap_map2.put("unit1", "个");
        top_mainleftmap_map2.put("label2", "项目金额");
        top_mainleftmap_map2.put("value2", sdmoney);
        top_mainleftmap_map2.put("unit2", "万元");
        top_mainleftmap_map2.put("value3", sdcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map2.put("unit3", "%");
        top_mainleftmap_map2.put("value4", sdmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map2.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map2);
        Map<String, Object> top_mainleftmap_map3 = new LinkedHashMap<>();
        top_mainleftmap_map3.put("title", "变电");
        top_mainleftmap_map3.put("label1", "项目数量");
        top_mainleftmap_map3.put("value1", bdcount);
        top_mainleftmap_map3.put("unit1", "个");
        top_mainleftmap_map3.put("label2", "项目金额");
        top_mainleftmap_map3.put("value2", bdmoney);
        top_mainleftmap_map3.put("unit2", "万元");
        top_mainleftmap_map3.put("value3", bdcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map3.put("unit3", "%");
        top_mainleftmap_map3.put("value4", bdmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map3.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map3);
        mainleftmap.put("leftArry", top_mainleftmap);
        Map<String, Object> top_mainleftmap_map4 = new LinkedHashMap<>();
        top_mainleftmap_map4.put("title", "配电");
        top_mainleftmap_map4.put("label1", "项目数量");
        top_mainleftmap_map4.put("value1", pdcount);
        top_mainleftmap_map4.put("unit1", "个");
        top_mainleftmap_map4.put("label2", "项目金额");
        top_mainleftmap_map4.put("value2", pdmoney);
        top_mainleftmap_map4.put("unit2", "万元");
        top_mainleftmap_map4.put("value3", pdcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map4.put("unit3", "%");
        top_mainleftmap_map4.put("value4", pdmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map4.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map4);
        Map<String, Object> top_mainleftmap_map5 = new LinkedHashMap<>();
        top_mainleftmap_map5.put("title", "用电");
        top_mainleftmap_map5.put("label1", "项目数量");
        top_mainleftmap_map5.put("value1", ydcount);
        top_mainleftmap_map5.put("unit1", "个");
        top_mainleftmap_map5.put("label2", "项目金额");
        top_mainleftmap_map5.put("value2", ydmoney);
        top_mainleftmap_map5.put("unit2", "万元");
        top_mainleftmap_map5.put("value3", ydcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map5.put("unit3", "%");
        top_mainleftmap_map5.put("value4", ydmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map5.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map5);
        Map<String, Object> top_mainleftmap_map6 = new LinkedHashMap<>();
        top_mainleftmap_map6.put("title", "信息通信");
        top_mainleftmap_map6.put("label1", "项目数量");
        top_mainleftmap_map6.put("value1", xxtxcount);
        top_mainleftmap_map6.put("unit1", "个");
        top_mainleftmap_map6.put("label2", "项目金额");
        top_mainleftmap_map6.put("value2", xxtxmoney);
        top_mainleftmap_map6.put("unit2", "万元");
        top_mainleftmap_map6.put("value3", xxtxcount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map6.put("unit3", "%");
        top_mainleftmap_map6.put("value4", xxtxmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map6.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map6);
        Map<String, Object> top_mainleftmap_map7 = new LinkedHashMap<>();
        top_mainleftmap_map7.put("title", "决策支持");
        top_mainleftmap_map7.put("label1", "项目数量");
        top_mainleftmap_map7.put("value1", jczccount);
        top_mainleftmap_map7.put("unit1", "个");
        top_mainleftmap_map7.put("label2", "项目金额");
        top_mainleftmap_map7.put("value2", jczcmoney);
        top_mainleftmap_map7.put("unit2", "万元");
        top_mainleftmap_map7.put("value3", jczccount.divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map7.put("unit3", "%");
        top_mainleftmap_map7.put("value4", jczcmoney.divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)));
        top_mainleftmap_map7.put("unit4", "%");
        top_mainleftmap.add(top_mainleftmap_map7);
        mainleftmap.put("leftArry", top_mainleftmap);
        //---------------mainleft-------------------END

        String sql5 = "SELECT unit.shortname shortname,SUM(totalcost) totalcost,SUM(yearcost) yearcost FROM t_info_unit unit LEFT JOIN t_tech_taskbook book " +
                "ON unit.name = book.unit where unit.type = 1 AND book.year = "+year+" GROUP BY unit.shortname";
        List<Map<String, Object>> unitList = queryInfoBySql(sql5);


//        List<String> OveralXlist = Arrays.asList("沈阳", "大连", "鞍山", "抚顺", "本溪", "丹东", "锦州", "营口", "阜新", "辽阳", "盘锦", "铁岭", "朝阳",
//                "超高压公司", "信通公司", "经研院", "电科院", "营销服务中心", "技培中心", "管培中心", "应急抢修中心");
        List<String> OveralXlist = new ArrayList<>();
        for (Map<String, Object> stringObjectMap : unitList) {
            OveralXlist.add(stringObjectMap.get("shortname").toString());
        }

        //---------------mainright-------------------START
        Map<String, Object> mainrightmap = new LinkedHashMap<>();
        Map<String, Object> top_mainrightmap = new LinkedHashMap<>();
        top_mainrightmap.put("name", "c_left");

        top_mainrightmap.put("dataName", OveralXlist);
        List<List<Map<String, Object>>> data = new ArrayList<>();
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (Map<String, Object> s : unitList) {
            Map<String, Object> dataMap = new LinkedHashMap<>();
            dataMap.put("name",s.get("shortname"));
            dataMap.put("value",s.get("totalcost"));
            dataMap.put("unit","万元");
            dataMap.put("total",22);
            dataList.add(dataMap);
        }
        data.add(dataList);
        top_mainrightmap.put("data", data);
        List<List<Map<String, Object>>> data2 = new ArrayList<>();
        List<Map<String, Object>> data2List = new ArrayList<>();
        for (Map<String, Object> s : unitList) {
            Map<String, Object> dataMap = new LinkedHashMap<>();
            dataMap.put("name",s.get("shortname"));
            dataMap.put("value",s.get("yearcost"));
            dataMap.put("unit","万元");
            dataMap.put("total",11);
            data2List.add(dataMap);
        }
        data2.add(data2List);
        top_mainrightmap.put("data2", data2);
        mainrightmap.put("left", top_mainrightmap);
        map.put("top", topmap);
        map.put("mainleft", mainleftmap);
        map.put("mainright", mainrightmap);
        res.put("data", map);
        res.put("code", 200);
        JSONObject json = new JSONObject(res);
        System.out.println(json);
        return res;
    }

    @PostMapping("TwoJson")
    @ResponseBody
    public Map<String, Object> getTwo(@RequestBody(required = false) Map parammap, HttpServletRequest request, HttpServletResponse response) {
        String year = "2023";
        if (parammap != null) {
            year = (String) parammap.get("year");
        }
        System.out.println("+++++++第二屏查询年份+++++" + year);

        String sql = "SELECT groupname groupname,count(*) count,SUM(money) money FROM t_tech_guide a WHERE a.year = "+year+" GROUP BY groupname";
        List<Map<String, Object>> maps = queryInfoBySql(sql);

        String sql1 = "SELECT SUM(money) as money,count(*) as count FROM t_tech_guide WHERE year ="+year+"";
        Map<String, Object> result1 = dldpResultService.queryInfoBySql2(sql1);

        BigDecimal totalMoney = new BigDecimal(result1.get("money").toString());
        BigDecimal totalCount = new BigDecimal(result1.get("count").toString());

        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> res = new LinkedHashMap<>();

        Map<String, Object> mainArry = new LinkedHashMap<>();
        List<Map<String, Object>> twoDataPageArry = new ArrayList<>();
        for (Map<String, Object> stringObjectMap : maps) {

            String groupname = stringObjectMap.get("groupname").toString();

            Map<String, Object> twoDataPageArry_map1 = new LinkedHashMap<>();
            twoDataPageArry_map1.put("isShow",true);
            twoDataPageArry_map1.put("label",groupname);
            twoDataPageArry_map1.put("title1",groupname+"类");
            twoDataPageArry_map1.put("title2","科技项目申报指南");
            twoDataPageArry_map1.put("prolabel1","项目数量");
            twoDataPageArry_map1.put("provalue1",stringObjectMap.get("count"));
            twoDataPageArry_map1.put("prounit1","个");
            twoDataPageArry_map1.put("provalue2",new BigDecimal(stringObjectMap.get("count").toString()).divide(totalCount,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")));
            twoDataPageArry_map1.put("prounit2","%");
            twoDataPageArry_map1.put("prolabel3","项目金额");
            twoDataPageArry_map1.put("provalue3",stringObjectMap.get("money"));
            twoDataPageArry_map1.put("prounit3","万元");
            twoDataPageArry_map1.put("provalue4",new BigDecimal(stringObjectMap.get("money").toString()).divide(totalMoney,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")));
            twoDataPageArry_map1.put("prounit4",'%');
            twoDataPageArry_map1.put("echarttitle","科技项目申报指南所属技术领域分布情况");
            twoDataPageArry_map1.put("echartunit","（单位：万元）");

            List<List<Map<String, Object>>> data = new ArrayList<>();
            List<Map<String, Object>> dataList = new ArrayList<>();

            String sql2 = "SELECT domain domain,SUM(money) money FROM t_tech_guide guide WHERE guide.year ="+year+" and guide.groupname = '"+groupname+"' GROUP BY domain";
            List<Map<String, Object>> resultList = queryInfoBySql(sql2);

            List<String> overalXlist = new ArrayList<>();
            for (Map<String, Object> objectMap : resultList) {
                overalXlist.add(objectMap.get("domain").toString());
                Map<String, Object> dataMap = new LinkedHashMap<>();
                dataMap.put("name",objectMap.get("domain").toString());
                dataMap.put("value",objectMap.get("money").toString());
                dataMap.put("unit","万元");
                dataMap.put("total",22);
                dataList.add(dataMap);
            }
            data.add(dataList);
            twoDataPageArry_map1.put("echartdata",data);

            List<Map<String, Object>> tabeltitledataMapList = new ArrayList<>();
            Map<String, Object> tabeltitledataMap = new LinkedHashMap<>();
            tabeltitledataMap.put("num","序号");
            tabeltitledataMap.put("name","项目名称");
            tabeltitledataMap.put("guide","指南组");
            tabeltitledataMap.put("field","所属技术领域");
            tabeltitledataMap.put("money","经费限额(万元)");
            tabeltitledataMap.put("time","项目起止时间");
            tabeltitledataMap.put("limit","限定范围");
            tabeltitledataMap.put("remarks","备注");
            tabeltitledataMapList.add(tabeltitledataMap);
            twoDataPageArry_map1.put("tabeltitledata",tabeltitledataMapList);

            String sql3 = "SELECT * FROM t_tech_guide guide WHERE guide.year ="+year+" and guide.groupname = '"+groupname+"'";
            List<Map<String, Object>> resultList1 = queryInfoBySql(sql3);

            List<Map<String, Object>> tablearryList = new ArrayList<>();
            for (Map<String, Object> objectMap : resultList1) {
                int i = 0;
                Map<String, Object> tablearryListMap = new LinkedHashMap<>();
                tablearryListMap.put("id",objectMap.get("num"));
                tablearryListMap.put("pname",objectMap.get("name"));
                tablearryListMap.put("pguide",objectMap.get("groupname"));
                tablearryListMap.put("pfield",objectMap.get("domain"));
                tablearryListMap.put("money",objectMap.get("money"));
                tablearryListMap.put("ptime",objectMap.get("period"));
                tablearryListMap.put("plimit",objectMap.get("limit"));
                tablearryListMap.put("premarks",objectMap.get("memo"));
                tablearryList.add(tablearryListMap);
            }
            twoDataPageArry_map1.put("tablearry",tablearryList);

            twoDataPageArry.add(twoDataPageArry_map1);
        }

        mainArry.put("twoDataPageArry",twoDataPageArry);
        map.put("mainArry",mainArry);
        res.put("data", map);
        res.put("code", 200);
        JSONObject json = new JSONObject(res);
        System.out.println(json);
        return res;
    }

    @PostMapping("ThreeJson")
    @ResponseBody
    public Map<String, Object> getThree(@RequestBody(required = false) Map parammap, HttpServletRequest request, HttpServletResponse response) {
        String year = "2023";
        if (parammap != null) {
            year = (String) parammap.get("year");
        }
        System.out.println("+++++++查询年份+++++" + year);

        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> res = new LinkedHashMap<>();

        Map<String, Object> query = new LinkedHashMap<>();
        query.put("type","a");
        query.put("entryname","b");
        map.put("query",query);

        String sql = "SELECT * FROM t_tech_taskbook book WHERE book.year ="+year+"";
        List<Map<String, Object>> resultList1 = queryInfoBySql(sql);

        List<Map<String, Object>> fromdata = new ArrayList<>();
        for (Map<String, Object> stringObjectMap : resultList1) {
            Map<String, Object> fromdataMap = new LinkedHashMap<>();
            fromdataMap.put("id",stringObjectMap.get("id"));
            fromdataMap.put("entryname",stringObjectMap.get("name"));
            fromdataMap.put("btnvalue1","查询专家评审");
            fromdataMap.put("btnvalue2","辅助决策评审");
            fromdataMap.put("experturl",URL+stringObjectMap.get("experturl"));
//            fromdataMap.put("experturl","/techres/2023YF-01/相关资料搜索.pdf");
            fromdataMap.put("decisionurl",URL+stringObjectMap.get("decisionurl"));
            fromdata.add(fromdataMap);
        }
        map.put("fromdata",fromdata);

        res.put("data", map);
        res.put("code", 200);
        JSONObject json = new JSONObject(res);
        System.out.println(json);
        return res;
    }

    @PostMapping("FourJson")
    @ResponseBody
    public Map<String, Object> getFour(@RequestBody(required = false) Map parammap, HttpServletRequest request, HttpServletResponse response) {
        String year = "2023";
        if (parammap != null) {
            year = (String) parammap.get("year");
        }
        System.out.println("+++++++查询年份+++++" + year);

        String sql1 = "SELECT count(*) count,SUM(totalcost) totalcost,SUM(yearcost) yearcost FROM t_tech_taskbook where year = '"+year+"'";
        Map<String, Object> result1 = dldpResultService.queryInfoBySql2(sql1);



        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> res = new LinkedHashMap<>();

        Map<String, Object> updata = new LinkedHashMap<>();
        List<Map<String, Object>> navdata = new ArrayList<>();
        Map<String, Object> navdataMap1 = new LinkedHashMap<>();
        navdataMap1.put("id","1");
        navdataMap1.put("label","下达科技项目任务数量");
        navdataMap1.put("value",result1.get("count"));
        navdataMap1.put("unit","个");
        navdata.add(navdataMap1);
        Map<String, Object> navdataMap2 = new LinkedHashMap<>();
        navdataMap2.put("id","2");
        navdataMap2.put("label","下达科技项目总经费");
        navdataMap2.put("value",result1.get("totalcost"));
        navdataMap2.put("unit","万元");
        navdata.add(navdataMap2);
        Map<String, Object> navdataMap3 = new LinkedHashMap<>();
        navdataMap3.put("id","3");
        navdataMap3.put("label","下达科技项目当年经费");
        navdataMap3.put("value",result1.get("yearcost"));
        navdataMap3.put("unit","万元");
        navdata.add(navdataMap3);

        updata.put("navdata",navdata);

        String sql5 = "SELECT unit.shortname shortname,SUM(totalcost) totalcost,SUM(yearcost) yearcost,count(*) count FROM t_info_unit unit LEFT JOIN t_tech_taskbook book " +
                "ON unit.name = book.unit where unit.type = 1 AND book.year = "+year+" GROUP BY unit.shortname";
        List<Map<String, Object>> unitList = queryInfoBySql(sql5);


        List<Map<String, Object>> echarsdata = new ArrayList<>();
        Map<String, Object> echarsdataMap1 = new LinkedHashMap<>();
        echarsdataMap1.put("titile","公司各单位下达科技项目任务数量统计");
        echarsdataMap1.put("unit","（单位：个）");
        List<List<Map<String, Object>>> data = new ArrayList<>();
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (Map<String, Object> s : unitList) {
            Map<String, Object> dataMap = new LinkedHashMap<>();
            dataMap.put("name",s.get("shortname"));
            dataMap.put("value",s.get("count"));
            dataMap.put("unit","万元");
            dataMap.put("total",22);
            dataList.add(dataMap);
        }
        data.add(dataList);
        echarsdataMap1.put("data",data);
        echarsdata.add(echarsdataMap1);
        Map<String, Object> echarsdataMap2 = new LinkedHashMap<>();
        echarsdataMap2.put("titile","公司各单位下达科技项目总经费统计");
        echarsdataMap2.put("unit","（单位：个）");
        List<List<Map<String, Object>>> data2 = new ArrayList<>();
        List<Map<String, Object>> dataList2 = new ArrayList<>();
        for (Map<String, Object> s : unitList) {
            Map<String, Object> dataMap = new LinkedHashMap<>();
            dataMap.put("name",s.get("shortname"));
            dataMap.put("value",s.get("totalcost"));
            dataMap.put("unit","万元");
            dataMap.put("total",32);
            dataList2.add(dataMap);
        }
        data2.add(dataList2);
        echarsdataMap2.put("data",data2);
        echarsdata.add(echarsdataMap2);
        Map<String, Object> echarsdataMap3 = new LinkedHashMap<>();
        echarsdataMap3.put("titile","公司各单位下达科技项目当年经费统计");
        echarsdataMap3.put("unit","（单位：个）");
        List<List<Map<String, Object>>> data3 = new ArrayList<>();
        List<Map<String, Object>> dataList3 = new ArrayList<>();
        for (Map<String, Object> s : unitList) {
            Map<String, Object> dataMap = new LinkedHashMap<>();
            dataMap.put("name",s.get("shortname"));
            dataMap.put("value",s.get("yearcost"));
            dataMap.put("unit","万元");
            dataMap.put("total",82);
            dataList3.add(dataMap);
        }
        data3.add(dataList3);
        echarsdataMap3.put("data",data3);
        echarsdata.add(echarsdataMap3);
        updata.put("echarsdata",echarsdata);

        List<Map<String, Object>> tableAarry = new ArrayList<>();

        String sql2 = "SELECT * FROM t_tech_taskbook book where book.year = "+year+"";
        List<Map<String, Object>> resList = queryInfoBySql(sql2);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月");

        for (Map<String, Object> stringObjectMap : resList) {
            Map<String, Object> tableAarryMap = new LinkedHashMap<>();
            tableAarryMap.put("id",stringObjectMap.get("num"));
            tableAarryMap.put("pqnum",stringObjectMap.get("num"));
            tableAarryMap.put("pqname",stringObjectMap.get("name"));
            tableAarryMap.put("pqptime",stringObjectMap.get("finishtime"));
            tableAarryMap.put("pqmoney",stringObjectMap.get("totalcost"));
            tableAarryMap.put("pqBackmoney",stringObjectMap.get("yearcost"));
            tableAarryMap.put("pqplimit",stringObjectMap.get("unit"));
            tableAarryMap.put("pqbtn1","评审专家");
            tableAarryMap.put("pqbtn2","评审意见");
            tableAarryMap.put("pqbtn3","任务书");
            tableAarryMap.put("experturl",URL+stringObjectMap.get("experturl"));
            tableAarryMap.put("decisionurl",URL+stringObjectMap.get("decisionurl"));
            tableAarryMap.put("taskbookturl",URL+stringObjectMap.get("taskbookturl"));
            tableAarry.add(tableAarryMap);
        }

        updata.put("tableAarry",tableAarry);


        map.put("updata",updata);

        res.put("data", map);
        res.put("code", 200);
        JSONObject json = new JSONObject(res);
        System.out.println(json);
        return res;
    }

    private List<Map<String, Object>> queryInfoBySql(String sql) {
        return dldpResultService.queryInfoBySql(sql);
    }

}
